package com.kindergarten.controller;

import com.kindergarten.pojo.TongJiVo;
import com.kindergarten.service.TongJiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("tongji-api")
public class TongJiController {

    @Autowired
    TongJiService tongJiService;

    //所有老师签到的总次数统计
    @RequestMapping(value = "empTongji")
    public String empTongji(Model model) {

        List<TongJiVo> ts = tongJiService.empTongji();
        List<String> names = new ArrayList<>();
        List<Integer> zc = new ArrayList<>();
        List<Integer> tq = new ArrayList<>();
        List<Integer> cd = new ArrayList<>();

        for (TongJiVo tongJi : ts) {
            names.add(tongJi.getUserName());
            zc.add(tongJi.getZhengChang());
            tq.add(tongJi.getTiQian());
            cd.add(tongJi.getChiDao());
        }

        model.addAttribute("names", names);
        model.addAttribute("zc", zc);
        model.addAttribute("tq", tq);
        model.addAttribute("cd", cd);

        return "tongJiEmp";
    }

    //所有老师签到的总次数统计
    @RequestMapping(value = "childTongji")
    public String childTongji(Model model) {

        List<TongJiVo> ts = tongJiService.childTongji();
        List<String> names = new ArrayList<String>();
        List<Integer> zc = new ArrayList<>();
        List<Integer> tq = new ArrayList<>();
        List<Integer> cd = new ArrayList<>();

        for (TongJiVo tongJi : ts) {
            names.add(tongJi.getName());
            zc.add(tongJi.getZhengChang());
            tq.add(tongJi.getTiQian());
            cd.add(tongJi.getChiDao());
        }

        model.addAttribute("names", names);
        model.addAttribute("zc", zc);
        model.addAttribute("tq", tq);
        model.addAttribute("cd", cd);

        return "tongJiXueSheng";
    }
}
